package com.itheima.demo02JDBC增_删_改数据重点;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/*
    建议Java里面写SQL语句,可以先在SQLYog中写好.复制到代码
 */
public class Demo02 {
    public static void main(String[] args) throws SQLException {
        // 1.注册驱动(自动注册)
        // 2.获取Connection连接
        // Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/day18", "root", "root");
        // 如果连接本机3306端口可以省略:localhost:3306
        Connection conn = DriverManager.getConnection("jdbc:mysql:///day18", "root", "root");

        // 3.获取Statement(小货车)
        Statement stmt = conn.createStatement();

        // 4.执行SQL语句
        // String sql = "INSERT INTO USER VALUES (NULL, 'tom', '123');";
        String sql = "UPDATE user SET name='tony' WHERE id=4;";

        // 5.处理结果
        int row = stmt.executeUpdate(sql);
        System.out.println("影响的行数: " + row);

        // 6.释放资源
        stmt.close();
        conn.close();
    }
}
